package hot100;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

public class Solution416 {
    public boolean canPartition(int[] nums) {
        int sum = 0;
        for (int x : nums) {
            sum += x;
        }
        if (sum % 2 != 0) return false;
        sum >>= 1;
        boolean[] dp = new boolean[sum + 1];
        dp[0] = true;
        for (int i = 0; i < nums.length; i++) {
            for (int j = sum; j >= nums[i]; j--) {
                if (dp[j - nums[i]]) {
                    dp[j] = true;
                    break;
                }
            }
        }
        return dp[sum];
    }
}
